package phoeics.authoryserver.webservice.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.ClientRegistrationException;
import org.springframework.security.oauth2.provider.NoSuchClientException;
import org.springframework.stereotype.Service;

import phoeics.authoryserver.webservice.service.RedisService;
@Service("redisClientDetailsService")
public class RedisClientDetailsService implements ClientDetailsService {
	private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(RedisClientDetailsService.class);
	@Autowired
	RedisService redisService;
	@Override
	public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
		final ClientDetails details = redisService.get(clientId,ClientDetails.class);
        if (details == null) {
            throw new NoSuchClientException("No client with requested id: " + clientId);
        }
        return details;
	}
}
